<?php

namespace Admin\Filter;

use Zend\InputFilter\Factory as InputFactory;     // <-- Add this import
use Zend\InputFilter\InputFilter;                 // <-- Add this import
use Zend\InputFilter\InputFilterAwareInterface;   // <-- Add this import
use Zend\InputFilter\InputFilterInterface;        // <-- Add this import

class Usuario implements InputFilterAwareInterface
{

    public $login;
    public $senha;
    public $nome;
    public $email;
    public $telefone;
    public $cpf;
    public $perfil;
    protected $inputFilter;                       // <-- Add this variable

    public function exchangeArray( $data )
    {
        $this->login    = (isset( $data['login'] )) ? $data['login'] : null;
        $this->senha    = (isset( $data['senha'] )) ? $data['senha'] : null;
        $this->nome     = (isset( $data['nome'] )) ? $data['nome'] : null;
        $this->email    = (isset( $data['email'] )) ? $data['email'] : null;
        $this->telefone = (isset( $data['telefone'] )) ? $data['telefone'] : null;
        $this->cpf      = (isset( $data['cpf'] )) ? $data['cpf'] : null;
        $this->perfil   = (isset( $data['perfil'] )) ? $data['perfil'] : null;

    }

    public function getArrayCopy()
    {
        return get_object_vars( $this );

    }

    // Add content to this method:
    public function setInputFilter( InputFilterInterface $inputFilter )
    {
        throw new \Exception( "Not used" );

    }

    public function getInputFilter()
    {
        if (!$this->inputFilter) {
            $inputFilter = new InputFilter();
            $factory     = new InputFactory();

            $inputFilter->add( $factory->createInput( array(
                        'name'       => 'login',
                        'required'   => true,
                        'filters'    => array(
                            array('name' => 'StripTags'),
                            array('name' => 'StringTrim'),
                        ),
                        'validators' => array(
                            array(
                                'name'    => 'StringLength',
                                'options' => array(
                                    'encoding' => 'UTF-8',
                                    'min'      => 1,
                                    'max'      => 100,
                                ),
                            ),
                        ),
            ) ) );

            $inputFilter->add( $factory->createInput( array(
                        'name'       => 'senha',
                        'required'   => true,
                        'filters'    => array(
                            array('name' => 'StripTags'),
                            array('name' => 'StringTrim'),
                        ),
                        'validators' => array(
                            array(
                                'name'    => 'StringLength',
                                'options' => array(
                                    'encoding' => 'UTF-8',
                                    'min'      => 1,
                                    'max'      => 50,
                                ),
                            ),
                        ),
            ) ) );

            $inputFilter->add( $factory->createInput( array(
                        'name'       => 'nome',
                        'required'   => true,
                        'filters'    => array(
                            array('name' => 'StripTags'),
                            array('name' => 'StringTrim'),
                        ),
                        'validators' => array(
                            array(
                                'name'    => 'StringLength',
                                'options' => array(
                                    'encoding' => 'UTF-8',
                                    'min'      => 1,
                                    'max'      => 100,
                                ),
                            ),
                        ),
            ) ) );

            $inputFilter->add( $factory->createInput( array(
                        'name'       => 'email',
                        'required'   => true,
                        'filters'    => array(
                            array('name' => 'StripTags'),
                            array('name' => 'StringTrim'),
                        ),
                        'validators' => array(
                            array(
                                'name'    => 'StringLength',
                                'options' => array(
                                    'encoding' => 'UTF-8',
                                    'min'      => 1,
                                    'max'      => 100,
                                ),
                            ),
                        ),
            ) ) );

            $inputFilter->add( $factory->createInput( array(
                        'name'       => 'telefone',
                        'required'   => true,
                        'filters'    => array(
                            array('name' => 'StripTags'),
                            array('name' => 'StringTrim'),
                            array('name' => 'Digits')
                        ),
                        'validators' => array(
                            array(
                                'name'    => 'StringLength',
                                'options' => array(
                                    'encoding' => 'UTF-8',
                                    'min'      => 1,
                                    'max'      => 100,
                                ),
                            ),
                        ),
            ) ) );

            $inputFilter->add( $factory->createInput( array(
                        'name'       => 'cpf',
                        'required'   => true,
                        'filters'    => array(
                            array('name' => 'StripTags'),
                            array('name' => 'StringTrim'),
                            array('name' => 'Digits')
                        ),
                        'validators' => array(
                            array(
                                'name'    => 'StringLength',
                                'options' => array(
                                    'encoding' => 'UTF-8',
                                    'min'      => 1,
                                    'max'      => 100,
                                ),
                            ),
                        ),
            ) ) );

            $inputFilter->add( $factory->createInput( array(
                        'name'       => 'perfil',
                        'required'   => true,
                        'filters'    => array(
                            array('name' => 'StripTags'),
                            array('name' => 'StringTrim'),
                        ),
                        'validators' => array(
                            array(
                                'name'    => 'StringLength',
                                'options' => array(
                                    'encoding' => 'UTF-8',
                                    'min'      => 1,
                                    'max'      => 100,
                                ),
                            ),
                        ),
            ) ) );

            $this->inputFilter = $inputFilter;
        }

        return $this->inputFilter;

    }

}
